class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        vector<int> tmp; //栈存储运算数
        for(int i = 0; i < tokens.size(); i++){
            int res;
            if(tokens[i] == "+") {
                int n = tmp.back();
                tmp.pop_back();
                int m = tmp.back();
                tmp.pop_back();
                res = n + m;
                tmp.push_back(res);
            }
            else if(tokens[i] == "-") {
                int n = tmp.back();
                tmp.pop_back();
                int m = tmp.back();
                tmp.pop_back();
                res = m - n;
                tmp.push_back(res);
            }
            else if(tokens[i] == "*") {
                int n = tmp.back();
                tmp.pop_back();
                int m = tmp.back();
                tmp.pop_back();
                res = n * m;
                tmp.push_back(res);
            }
            else if(tokens[i] == "/") {
                int n = tmp.back();
                tmp.pop_back();
                int m = tmp.back();
                tmp.pop_back();
                res = m / n;
                tmp.push_back(res);
            }
            else{
                tmp.push_back(stoi(tokens[i]));
            }
        }
        return tmp.back();
    }
};